from socket import *
ADDR=("127.0.0.1",8888)
class DictView1:
    def __init__(self):
        self.dictview2=DictView2()
    def display_menu_1(self):
        '''
        1级显示菜单
        '''
        a="""
==========================小甘词典===========================
                1.登录   2.注册  3.退出
============================================================
        """
        print(a)

    def select_menu_1(self):
        """
        1级选择菜单
        """
        cmd=int(input("请输入选项:"))
        if cmd==1:
            self.login()
        if cmd==2:
            self.register()
        if cmd==3:
            self.quit()
        else:
            print("请输入正确选项")
    def register(self):
        """
        注册
        """
        pass
    def login(self):
        """
        登入
        """
        if True:
            self.dictview2.display_menu_2()
            self.dictview2.select_menu_2()
        elif False:
             self.display_menu_1()


    def quit(self):
        """
        退出
        """
    def main(self):
        while True:
            dictview1.display_menu_1()
            dictview1.select_menu_1()

class DictView2:
    def __init__(self):
        self.tcpclient=TcpClient()
    def display_menu_2(self):
        """
        二级显示菜单
        """
        print("1.查单词")
        print("2.查看历史记录")
        print("3.注销")
    def select_menu_2(self):
        """
        二级选择菜单
        """
        item=int(input("请输入选项进行操作："))
        if item == 1:
            self.inquire()
        if item==2:
            self.hitory()
        if item==3:
            self.logout()
    def inquire(self):
        """
        查询方法：需和客户端交互
        """
        self.tcpclient.send_request()
        pass
    def logout(self):
        """
        注销，返回一级登录界面
        """
        dictview1=DictView1()
        dictview1.display_menu_1()
        dictview1.select_menu_1()
    def hitory(self):
        pass
class TcpClient:
    """
    tcp网络通信
    """
    def __init__(self):
        self.sock=self.create_sock()
    def create_sock(self):
        sock=socket()
        sock.connect(ADDR) #创建链接
        return sock
    def send_request(self):
        """
        发送tcp请求
        """
        # self.sock.send()
    def take_in_response(self):
        """
        接收tcp响应,并且根据请求分情况判断
        """
        self.sock.recv(1024)

if __name__ == '__main__':
    dictview1=DictView1()
    dictview1.main()
